import CommonJsLoader from './SourceLoader';
import File from '../file/File';
import SourceLoader from './SourceLoader';

export default class CssLoader extends SourceLoader {
    async load(file: File) {
        file.contents = this.wrapCss(file.contents || '');
        await super.load(file);
    }

    wrapCss(code: string) {
        return `\n\nvar style=document.createElement("style");
    style.innerHTML="${code
                .replace(/\\/g, '\\\\')
                .replace(/"/g, '\\"')
                .replace(/\r/g, '\\r')
                .replace(/\n/g, '\\n')
                .replace(/\t/g, '\\t')
            }";
    document.body.appendChild(style);`;
    }
}